import {Lunar} from "lunar-javascript";

export function getDayOfYear(date) {
  const startOfYear = new Date(date.getFullYear(), 0, 0);
  const diff = date - startOfYear;
  const oneDay = 1000 * 60 * 60 * 24;
  return Math.floor(diff / oneDay);
}

export function getDayOfWeek(date) {
  const daysOfWeek = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  return daysOfWeek[date.getDay()];
}

export function getWeekNumber(date) {
  const startOfYear = new Date(date.getFullYear(), 0, 1);
  const daysOffset = (date.getDay() - startOfYear.getDay() + 7) % 7;
  const weekNumber = Math.ceil(((date - startOfYear) / 86400000 + daysOffset + 1) / 7);
  return weekNumber;
}

export function getZodiac(year){
  const animals = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'];
  return animals[(year-4) % 12];
}

export function getChuXi(year) {
  // 创建指定年份的农历12月30日
  const lunarDate = Lunar.fromYmd(year, 12, 29);
  // 转换为公历日期
  const solarDate = lunarDate.getSolar();
  return new Date(solarDate.getYear(), solarDate.getMonth() - 1, solarDate.getDay())
}

